package com.zyn.inventory.management.services;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.zyn.inventory.management.dao.BaseDao;

@Transactional(propagation = Propagation.REQUIRED)
public abstract class EntityServiceImpl<Entity, EntityDao extends BaseDao<Entity>>
		implements EntityService<Entity> {
	protected EntityDao entityDao;

	public EntityDao getEntityDao() {
		return entityDao;
	}

	public abstract void setEntityDao(EntityDao entityDao);

	public void add(Entity entity) {
		this.entityDao.add(entity);
	}

	@Transactional(readOnly=true)
	public Entity get(Long id) {
		return this.entityDao.get(id);
	}

	public void delete(Long id) {
		this.entityDao.deleteById(id);
	}

	public void update(Entity entity) {
		this.entityDao.update(entity);
	}

	@Transactional(readOnly=true)
	public boolean doesEntityExist(Long id) {
		return this.get(id) != null;
	}

}
